package com.xjoyt.pay.master.security;

import java.util.UUID;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;

public class SimpleAuthSecurity implements AuthSecurity {

	@Override
	public boolean isSuccess(String password, PassportHex hex) {
		String pwd = StringUtils.isBlank(hex.key) ? password : (password + hex.key);
		String md5Hex = DigestUtils.md5Hex(pwd);
		return md5Hex.equals(hex.password);
	}

	@Override
	public PassportHex createHex(String password) {
		String key = UUID.randomUUID().toString().substring(0, 4).toUpperCase();
		String pwd = DigestUtils.md5Hex(password + key);
		return new PassportHex(pwd, key);
	}

}
